package com.wanglibao.woodtrade.woodtrade.ui.activity;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.wanglibao.woodtrade.woodtrade.R;
import com.wanglibao.woodtrade.woodtrade.ui.activity.adapter.ItemLvSupplyAndDemendAdapter;
import com.wanglibao.woodtrade.woodtrade.util.ToastUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class SupplyAndDemendActivity extends BaseActivity {

    @Bind(R.id.rb_qg_trade_fragment)
    RadioButton mRbQgTradeFragment;
    @Bind(R.id.rb_cs_trade_fragment)
    RadioButton mRbCsTradeFragment;
    @Bind(R.id.rg_trade_fragment)
    RadioGroup mRgTradeFragment;
    @Bind(R.id.lv_trade_fragment)
    ListView mLvTradeFragment;
//    =====================================
    ItemLvSupplyAndDemendAdapter mItemLvSupplyAndDemendAdapter;
    List<String> mlist = new ArrayList<>();
    List<String> mList1=new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_supply_and_demend);
        ButterKnife.bind(this);
        for (int i = 0; i < 10; i++) {
            mlist.add("我要供货");
        }
        for (int i = 0; i < 5; i++) {
            mList1.add("我要买货");
        }
        initData();
    }
    private void initData() {
        tvBack.setText("");
        tvTitle.setText("求购信息");
        tvRight.setText("发布");
        this.addViewClicklistener(mRbCsTradeFragment,mRbQgTradeFragment);
        tvRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtil.createNormalToast("发布东西！");
            }
        });
        mItemLvSupplyAndDemendAdapter = new ItemLvSupplyAndDemendAdapter(this, mlist);
        mLvTradeFragment.setAdapter(mItemLvSupplyAndDemendAdapter);
    }
    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch(v.getId()){
            //出售信息
            case R.id.rb_cs_trade_fragment:
                mItemLvSupplyAndDemendAdapter.setList(mList1);
                mItemLvSupplyAndDemendAdapter.notifyDataSetChanged();
                break;
            //求购信息
            case R.id.rb_qg_trade_fragment:
                mItemLvSupplyAndDemendAdapter.setList(mlist);
                mItemLvSupplyAndDemendAdapter.notifyDataSetChanged();
                break;
            default:
                break;
        }
    }

}
